//
//  ViewController.m
//  fp
//
//  Created by xingshuai on 2020/10/9.
//

#import "ViewController.h"

#import "TwoViewController.h"
#import "FourViewController.h"
#import "SixViewController.h"
#import "SevenViewController.h"
#import "TableViewCell.h"
#import "UserTopView.h"

@interface ViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) NSArray *imgList;
@property (nonatomic, strong) NSArray *textList;
@property (nonatomic, strong) UserTopView *topView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.isHiddenNav = YES;
            
    _imgList = @[@"user_classroom",@"user_history",@"user_set",@"user_feed"];
    _textList = @[@"我的课程",@"播放历史",@"设置",@"意见反馈"];
    [self creatViewUI];

}
-(void)creatViewUI {
    [self.view addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.view).offset(24);
    }];
    
    self.table.tableHeaderView = self.topView;
}

-(UserTopView *)topView {
    if (!_topView) {
        _topView = [[UserTopView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
    }
    return _topView;
}

-(UITableView *)table {
    if (!_table) {
        _table = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _table.delegate = self;
        _table.dataSource = self;
        _table.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _table.tableFooterView = [[UIView alloc]init];
    }
    return _table;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _textList.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellid = @"cellid";
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (!cell) {
        cell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
    }
    
    [cell cellLoadImg:[self.imgList objectAtIndex:indexPath.row] cellStr:[self.textList objectAtIndex:indexPath.row]];

    if (indexPath.row == 0) {
        [tableView selectRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
        [self tableView:self.table didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    }
    
    cell.selectedBackgroundView = [[UIView alloc]initWithFrame:cell.contentView.bounds];
    cell.selectedBackgroundView.backgroundColor = customColor(239, 243, 255, 1);
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        TwoViewController *vc = [[TwoViewController alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        vc.navString = [_textList objectAtIndex:indexPath.row];
        [self.splitViewController showDetailViewController:nav sender:self];
    } else if (indexPath.row == 1) {
//        FourViewController *vc = [[FourViewController alloc]init];
//        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
//        vc.navString = [_textList objectAtIndex:indexPath.row];
//        [self.splitViewController showDetailViewController:nav sender:self];
        
        TwoViewController *vc = [[TwoViewController alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        vc.navString = [_textList objectAtIndex:indexPath.row];
        vc.isHisTory = YES;
        [self.splitViewController showDetailViewController:nav sender:self];
        
    } else if (indexPath.row == 2) {
        SevenViewController *vc = [[SevenViewController alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        vc.navString = [_textList objectAtIndex:indexPath.row];
        [self.splitViewController showDetailViewController:nav sender:self];
    } else {
        SixViewController *vc = [[SixViewController alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        vc.navString = [_textList objectAtIndex:indexPath.row];
        [self.splitViewController showDetailViewController:nav sender:self];
        
    }
}



@end
